﻿package com.tudou.home.view
{
    import com.tudou.events.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.privacy.*;
    import flash.display.*;
    import org.puremvc.as3.patterns.mediator.*;

    public class PrivacyMediator extends Mediator
    {
        private var parent:Sprite;
        private var privacyPanel:PrivacyPanel;
        public static const NAME:String = "PrivacyPanel";

        public function PrivacyMediator(param1:Sprite)
        {
            this.parent = param1;
            super(NAME, param1);
            this.parent.visible = false;
            return;
        }// end function

        public function showWrong() : void
        {
            if (privacyPanel == null)
            {
                show();
            }
            else
            {
                privacyPanel.status = PrivacyPanel.FAIL;
            }
            return;
        }// end function

        public function succeed() : void
        {
            if (privacyPanel)
            {
                privacyPanel.status = PrivacyPanel.SUCCESS;
            }
            clear();
            return;
        }// end function

        public function clear() : void
        {
            if (privacyPanel)
            {
                parent.removeChild(privacyPanel);
                privacyPanel.removeEventListener(PrivacyPanelEvent.SUBMIT, submitHlr);
                privacyPanel = null;
                parent.visible = false;
            }
            return;
        }// end function

        private function submitHlr(event:PrivacyPanelEvent) : void
        {
            var _loc_2:* = PageInfo.getInstance();
            _loc_2.password = privacyPanel.password;
            sendNotification(V2CommandSet.START_LOAD);
            privacyPanel.status = PrivacyPanel.SUBMITTING;
            return;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            parent.x = int((param1 - PlayerConsts.PRIVACY_WIDTH) / 2);
            parent.y = int((param2 - PlayerConsts.PRIVACY_HEIGTH) / 2);
            return;
        }// end function

        public function show() : void
        {
            var _loc_1:* = PageInfo.getInstance();
            clear();
            privacyPanel = new PrivacyPanel(_loc_1, _loc_1.title);
            privacyPanel.status = PrivacyPanel.INIT;
            parent.addChild(privacyPanel);
            privacyPanel.addEventListener(PrivacyPanelEvent.SUBMIT, submitHlr);
            parent.visible = true;
            return;
        }// end function

    }
}
